/**
 * 加载更多数据的指令
 */
 export default {
	install(Vue) {
		Vue.mixin({
			directives: {
				loadmore: {
					bind(el, binding) {
						let bindTime;
						clearTimeout(bindTime)
						bindTime = window.setTimeout(function () {
							let selectWrap = el.querySelector(".ant-table-body");
							if (!selectWrap) selectWrap = el.querySelector(".el-table__body-wrapper");
							var lastScrollTop = 0;
							selectWrap.addEventListener("scroll", function () {
								let offsetValue = 20;
									if(this.scrollTop == 0) {
										binding.value('up', this);
										return false;
									}
									if (lastScrollTop != this.scrollTop) {
										lastScrollTop = this.scrollTop;
										const scrollDistance = this.scrollHeight - this.scrollTop - this.clientHeight;
										if (scrollDistance <= offsetValue) {
											binding.value('down', this);
										}
									}
							}, false);
						}, 200);
					}
				}
			}
		});
	}
};